package com.abbas.abchat.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;

import com.abbas.abchat.AbChatApplication;
import com.abbas.abchat.R;
import com.abbas.abchat.dao.FriendRoundDao;
import com.abbas.abchat.dao.impl.FriendRoundImpl;
import com.abbas.abchat.entity.FriendRound;

import java.text.SimpleDateFormat;
import java.util.Date;

public class EditFriendRoundActivity extends BaseActivity implements View.OnClickListener{

    private ImageButton ibBack;
    private Button finish;
    private EditText et;

    private FriendRoundDao friendRoundDao;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_edit_friend_round;
    }

    @Override
    protected void init() {
        ibBack = (ImageButton) findViewById(R.id.ib_back);
        finish = (Button) findViewById(R.id.finish);
        et = (EditText) findViewById(R.id.et);

        friendRoundDao = new FriendRoundImpl(this);

        ibBack.setOnClickListener(this);
        finish.setOnClickListener(this);

    }

    @Override
    protected void initEvent() {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.ib_back:
                finishThis();
                break;
            case R.id.finish:
                String content = et.getText().toString().trim();
                if (!TextUtils.isEmpty(content)){
                    FriendRound friendRound = new FriendRound();
                    friendRound.setContent(content);
                    friendRound.setpId(AbChatApplication.getAccount().getId());
                    friendRound.setPubDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
                    friendRound.setLocation("宜春");
                    long insertResult = -1;
                    try {
                        insertResult = friendRoundDao.insert(friendRound);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    if (insertResult == -1){
                        showMessage("数据错误");
                    }

                    finishThis();
                }
                break;
        }
    }
}